﻿using BaoVeThanhDia.GamePlay.Monsters;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace BaoVeThanhDia.GamePlay.Towers
{
    class SoulTower : Tower
    {
        private int countDraw;// biến phụ đếm thời gian
        private Texture2D imageRoot, imageFrozen;
        public SoulTower() { }
        public SoulTower(Vector2 index, int level, int type)
        {
            ValueBuff = 0;
            countDraw = 0;
            setIndex(index);
            setLevel(level, type);
            weapons = new List<Weapon>();
            setelement();
        }
        public override void Load(ContentManager content)
        {
            scale = 100 / 100f;
            Image = content.Load<Texture2D>("images/towers/soul/" + Level.ToString() + (Type == 0 ? "" : Type.ToString()));
            imageRoot = content.Load<Texture2D>("images/towers/soul/root" + (Type == 0 ? "" : Type.ToString()));
            imageFrozen = content.Load<Texture2D>("images/towers/soul/frozen");
        }
        public override void setLevel(int level, int type)
        {
            Level = level;
            Type = type;
            if (Type == 1) Effect = "Slow";
            else if (Type == 2) Effect = "None";
            else Effect = "None";
        }
        public override void Draw(ContentManager cont, SpriteBatch sprite)
        {
            sprite.Draw(imageRoot, (Position + new Vector2(-13, -45)) * GamePage.Scale + GamePage.Dolech, new Rectangle((countDraw / 5) % 6 * 100, 0, 100, 100), Color.White, 0f, Vector2.Zero, 1.5f * GamePage.Scale, SpriteEffects.None, 0f);
            sprite.Draw(Image, (Position + new Vector2(17, -50)) * GamePage.Scale + GamePage.Dolech, new Rectangle(0, 0, 100, 137), Color.White, 0f, Vector2.Zero, scale * GamePage.Scale, SpriteEffects.None, 0f);
            if (Type == 1) sprite.Draw(imageFrozen, (Position + new Vector2(30, -80)) * GamePage.Scale + GamePage.Dolech, new Rectangle((countDraw / 5) % 4 * 100, 0, 100, 157), Color.White, 0f, Vector2.Zero, 0.9f * GamePage.Scale, SpriteEffects.None, 0f);
            countDraw++;
            if (countDraw >= 120) countDraw = 0;
        }
        public override void OptionDraw(SpriteBatch sprite, Vector2 posi, Vector2 dolech, float scale, bool isTouch)
        {
            sprite.Draw(imageRoot, posi + dolech + new Vector2(-36, 0) * scale, new Rectangle((countDraw / 5) % 6 * 100, 0, 100, 100), Color.White, 0f, Vector2.Zero, 1.5f * scale, SpriteEffects.None, 0f);
            sprite.Draw(Image, posi + dolech, new Rectangle(0, 0, 100, 137), Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
            if (Type == 1) sprite.Draw(imageFrozen, posi + new Vector2(30, 0) * scale + dolech, new Rectangle((countDraw / 5) % 4 * 100, 0, 100, 157), Color.White, 0f, Vector2.Zero, 0.9f * scale, SpriteEffects.None, 0f);
            if (isTouch)
            {
                countDraw++;
                if (countDraw >= 120) countDraw = 0;
            }
        }
        public override void Ban()
        {
            if ((int)countDraw % 30 == 0)
            {
                for (int i = 0; i < GamePage.monsters.Count; i++)
                {
                    if (Vector2.Distance(Position, GamePage.monsters[i].getPosition()) <= Range * 128 && GamePage.monsters[i].getCurHP() > 0)
                    {
                        GamePage.monsters[i].setTruMau(0, 0, Effect, countEffect, 60);
                    }
                }
            }
        }
        public override void setelement()
        {
            if (Level == 1)
            {
                Price = 150;
                PriceBought = 150;
                PhysicDame = 20;
                MagicDame = 20;
                Speed = 1;
                Range = 2f;
                countEffect = 0;
            }
            else if (Level == 2)
            {
                Price = 100;
                PriceBought = 250;
                PhysicDame = 27;
                MagicDame = 27;
                Speed = 1f;
                Range = 2.3f;
                countEffect = 0;
            }
            else if (Level == 3)
            {

                PriceBought = 400;
                if (Type == 1)
                {
                    Price = 150;
                    PhysicDame = 30;
                    MagicDame = 30;
                    Speed = 1f;
                    countEffect = 25;
                    Range = 2.3f;
                }
                else
                {
                    Price = 150;
                    PhysicDame = 50;
                    MagicDame = 50;
                    Speed = 1f;
                    countEffect = 0;
                    Range = 2.3f;
                }
            }
            else
            {
                PriceBought = 500;
                if (Type == 1)
                {
                    Range = 2.5f;
                    Price = 100;
                    PhysicDame = 45;
                    MagicDame = 45;
                    Speed = 1f;
                    countEffect = 50;
                }
                else
                {
                    Range = 2.5f;
                    Price = 100;
                    PhysicDame = 65;
                    MagicDame = 65;
                    Speed = 1f;
                    countEffect = 0;
                }
            }
        }
        public override float getPriceUpGrade(int level, int type)
        {
            return new SoulTower(Vector2.Zero, level, type).Price;
        }
        public override void DrawPictureUpGrade(int level, int type, ContentManager cont, SpriteBatch sprite, Vector2 posi)
        {
            SoulTower temp = new SoulTower(Vector2.Zero, level, type);
            temp.Load(cont);
            temp.OptionDraw(sprite, posi + new Vector2(4, -20) * GamePage.Scale, GamePage.Dolech,0.8f * GamePage.Scale, false);
        }
    }
}
